import math 
def prime(x):
    isPrime=True
    for i in range(2,math.ceil(x**0.5)+1):
        if x%i==0:
            isPrime=False
            break
    return isPrime

def isPalindromic(x):
    isPalindromic=True
    n=x
    m=0
    while n!=0:
        m=m*10+n%10
        n//=10
    if m==x:
        isPalindromic=True
    else:
        isPalindromic=False
    return isPalindromic

def reverse(x):
    m=0
    while x!=0:
        m=m*10+x%10
        x//=10
    return m

def main():
    num_start=int(input())
    num_end=int(input())
    for i in range(num_start,num_end+1):
        if not isPalindromic(i):
            if prime(i)and prime(reverse(i)):
                print(i)

main()